﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Infrastructure.MyException
{
    public class ShowUserLogicException : Exception
    {

        public Dictionary<string, List<string>> SonErrs { get; set; } = [];

        public ShowUserLogicException(string errmsg) : base(errmsg)
        {

        }
        public ShowUserLogicException(Exception ex) : base(ex.Message)
        {

        }

        public ShowUserLogicException(ShowUserLogicException ex) : base(ex.Message)
        {
            this.SonErrs = ex.SonErrs;
        }

        public ShowUserLogicException AddSonMessage(string code, string msg)
        {
            if (SonErrs.TryGetValue(code, out var value))
            {
                value.Add(msg);
            }
            else
            {
                SonErrs.TryAdd(code, new List<string> { msg });
            }

            return this;
        }

        public ShowUserLogicException AddSonMessage(string code, List<string> msg)
        {
            if (SonErrs.TryGetValue(code, out var value))
            {
                value.AddRange(msg);
            }
            else
            {
                SonErrs.TryAdd(code, msg);
            }

            return this;
        }

        public ShowUserLogicException AddSonMessage(Dictionary<string, string> errs)
        {
            foreach (var a in errs)
            {
                AddSonMessage(a.Key, a.Value);
            }

            return this;
        }

        public ShowUserLogicException AddSonMessage(Dictionary<string, List<string>> errs)
        {
            foreach (var a in errs)
            {
                AddSonMessage(a.Key, a.Value);
            }

            return this;
        }
    }

}
